#include <stdio.h>
#include <stdlib.h>
#include "stack_queue.h"

// Function to test sequential stack
void test_sq_stack() {
    sq_stack stack;
    int data;

    // Initialize stack
    sqs_init(&stack);

    // Push operation
    printf("Testing sqs_push...\n");
    for (int i = 0; i < 5; i++) {
        if (sqs_push(&stack, i) == 0) {
            printf("Pushed %d into the stack.\n", i);
        }
    }

    // Pop operation
    printf("Testing sqs_pop...\n");
    while (sqs_pop(&stack, &data) == 0) {
        printf("Popped %d from the stack.\n", data);
    }
}

// Function to test linked stack
void test_ls_stack() {
    lslist list;
    int data;

    // Initialize stack
    if (ls_init(&list) == 0) {
        printf("Linked stack initialized.\n");
    }

    // Push operation
    printf("Testing ls_push...\n");
    for (int i = 0; i < 5; i++) {
        if (ls_push(&list, i) == 0) {
            printf("Pushed %d into the linked stack.\n", i);
        }
    }

    // Pop operation
    printf("Testing ls_pop...\n");
    while (ls_pop(&list, &data) == 0) {
        printf("Popped %d from the linked stack.\n", data);
    }

    // Free memory
    free(list);
}

// Function to test sequential queue
void test_sq_queue() {
    sq_queue queue;
    int data;

    // Initialize queue
    sqq_init(&queue);

    // Enqueue operation
    printf("Testing sqq_in...\n");
    for (int i = 0; i < 5; i++) {
        if (sqq_in(&queue, i) == 0) {
            printf("Enqueued %d into the queue.\n", i);
        }
    }

    // Dequeue operation
    printf("Testing sqq_out...\n");
    while (sqq_out(&queue, &data) == 0) {
        printf("Dequeued %d from the queue.\n", data);
    }

    // Test queue length
    printf("Queue length: %d\n", sqq_length(&queue));
}

// Function to test linked queue
void test_lq_queue() {
    lqlist list;
    int data;

    // Initialize queue
    if (lq_init(&list) == 0) {
        printf("Linked queue initialized.\n");
    }

    // Enqueue operation
    printf("Testing lq_in...\n");
    for (int i = 0; i < 5; i++) {
        if (lq_in(&list, i) == 0) {
            printf("Enqueued %d into the linked queue.\n", i);
        }
    }

    // Dequeue operation
    printf("Testing lq_out...\n");
    while (lq_out(&list, &data) == 0) {
        printf("Dequeued %d from the linked queue.\n", data);
    }

    // Test queue length
    printf("Linked queue length: %d\n", lq_length(&list));

    // Destroy queue
    lq_destroy(&list);
}

int main() {
    // Test sequential stack
    test_sq_stack();
    printf("\n");

    // Test linked stack
    test_ls_stack();
    printf("\n");

    // Test sequential queue
    test_sq_queue();
    printf("\n");

    // Test linked queue
    test_lq_queue();

    return 0;
}